<template>
  <base-layout
    :dialog-title="dialogTitle"
    :dialog-visible="dialogVisible"
    @dialog-close="dialogClose"
  >
    <template #searchPanel>
      <search-panel
        v-slot="{ form }"
        :addPer="'inStorage:save'"
        :selectPer="'inStorage:page'"
        addTitle="新增入库"
        @insert="add"
        @search="search"
        :showSearchButton="true"
        :showAddButton="true"
        :showExportButton="true"
        @export="handleDataExport(InStorage,'入库数据')"
      >
        <Job-shop v-model="form.storeId" placeholder="所属门店" />
        <el-select
          clearable
          style="width: 200px"
          v-model="form.storageType"
          placeholder="采购入库"
        >
          <el-option
            v-for="item in dict['入库类型']"
            :key="item.index"
            :value="item.value"
            :label="item.text"
          />
        </el-select>
        <el-input
          v-model="form.likeName"
          clearable
          placeholder="入库编号"
          style="width: 200px"
        />
      </search-panel>
    </template>
    <template #contentPanel>
      <data-table
        :value="tableData"
        :total-count="totalCount"
        :has-action="true"
        :table-column-attributes="tableColumnAttributes"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :width="160"
        @row-dblclick="view"
      >
        <template #action="{ row }">
          <el-col :span="8">
            <i
              v-if="row.inStorageType == '采购入库' && row.status == '未入库'"
              class="el-icon-back pointer"
              title="退货"
              style="cursor: pointer"
              @click="handleDataUpdateEdit(row, '退货')"
            ></i>
            &nbsp
          </el-col>
          <el-col :span="8">
            <i
              v-if="row.status != '已入库'"
              class="el-icon-edit"
              title="编辑"
              style="cursor: pointer"
              v-permission="'inStorage:update'"
              @click="handleDataUpdateEdit(row, '编辑')"
            ></i>
          </el-col>
          <el-col :span="8">
            <i
              class="el-icon-delete"
              title="删除"
              style="color: red; cursor: pointer"
              v-permission="'inStorage:del'"
              @click="handleDataDelete(row)"
            ></i>
          </el-col>
        </template>
      </data-table>
    </template>
    <template #dialog>
      <dialog-view-detail :id="viewId" />
    </template>
  </base-layout>
</template>
<script>
import baseMixin from "@/mixins/base";
import { page, deleteById } from "@/api/after-sale/storehouseManage/inOfStockManage";
import { getDict } from "@/utils";
import DialogViewDetail from "./view/index";
export default {
  components: {
    DialogViewDetail,
  },
  mixins: [
    baseMixin({
      idName: "id",
      findData: page,
      dataName: ["content", "totalRecords"],
      format(res) {
        return res.map((data) => {
          return data;
        });
      },
      deleteData: deleteById,
    }),
  ],
  data() {
    return {
      tableColumnAttributes: [
        { name: "所属门店", value: "storeName", type: "text" },
        { name: "入库编号", value: "inStorageCode", type: "text" },
        { name: "入库类型", value: "inStorageType", type: "text" },
        { name: "入库仓库", value: "storageName", type: "text" },
        { name: "仓库编号", value: "storageCode", type: "text" },
        { name: "入库负责人", value: "userName", type: "text" },
        { name: "负责人联系方式", value: "phone", type: "text" },
        { name: "单据日期", value: "receiptsTime", type: "text" },
        { name: "入库配件数量", value: "partsNum", type: "text" },
        { name: "入库总金额", value: "amount", type: "text" },
        { name: "入库备注", value: "remark", type: "text" },
        { name: "入库状态", value: "status", type: "text" },
        { name: "录入时间", value: "createTime", type: "text" },
      ],
      dict: [],
      viewId: "",
    };
  },
  methods: {
    add() {
      this.$router.push({ path: "/partsStock/partsStockManage/addInOfStockManage" });
    },
    handleDataUpdateEdit(row, type) {
      if (type === "编辑") {
        this.$router.push({
          path: "/partsStock/partsStockManage/editInOfStockManage",
          query: {
            id: row.id,
          },
        });
      } else if (type === "退货") {
        this.$router.push({
          path: "/partsStock/partsStockManage/addPurchaseReturn",
          query: {
            id: row.workOrderCode,
            type: true,
          },
        });
      }
    },
    search(form) {
      this.searchOptions = form;
      this.currentPage = 1;
      this.setTableData();
    },
    // 查看入库
    view(row) {
      this.viewId = row.id;
      this.handleDataInsert("入库详情");
    },
  },
  mounted() {
    this.dict = getDict(["入库类型"]);
  },
};
</script>
